//
//  YTDiscoverViewController.m
//  CllForIOS
//
//  Created by qiyun on 2018/3/6.
//  Copyright © 2018年 aRui. All rights reserved.
//

#import "YTDiscoverViewController.h"

#import "YTHomeCollectionCell.h"
#import "ImagePlayerView.h"
#import "YTDisCollectionCell.h"

#import "YTAdRecommendVC.h"
#import "YTDisNewsVC.h"
#import "YTDisNoticeVC.h"
#import "YTWebViewVC.h"
#import "YTHcollectionheader.h"
@interface YTDiscoverViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic ,strong) UICollectionView * collectionView;
@property (nonatomic ,strong) NSArray * titlearray;
@property (nonatomic ,strong) NSArray * iconarray;
@end

@implementation YTDiscoverViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLabel.text = @"发现";
    self.lineView.hidden=YES;
    [self.view addSubview:self.collectionView];
    
    self.titlearray=@[@"开奖公告",@"赛事公告",@"赛事资讯",@"名人榜单",@"比分直播",@"晒单宣传",@"活动一览",@"更多"];
    self.iconarray=@[@"findicon1",@"findicon2",@"findicon3",@"findicon4",@"findicon5",@"findicon6",@"findicon7",@"findicon8"];
    
    [self.collectionView reloadData];
    
    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, k_NavigationHeight, SCREEN_W, 12)];
    view.backgroundColor=RGBA(236, 236, 236);
    [self.view addSubview:view];
}
- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout * flowLayout=[[UICollectionViewFlowLayout alloc]init];
        flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        flowLayout.headerReferenceSize = CGSizeMake(SCREEN_W, AfW(40));
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, k_NavigationHeight+12, SCREEN_W, SCREEN_H-k_NavigationHeight-k_TabBarHeight-12) collectionViewLayout:flowLayout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.backgroundColor = [UIColor whiteColor];
        
        [_collectionView registerClass:[YTHomeCollectionCell class] forCellWithReuseIdentifier:@"YTHomeCollectionCell"];
        [_collectionView registerClass:[YTDisCollectionCell class] forCellWithReuseIdentifier:@"YTDisCollectionCell"];
        [_collectionView registerClass:[YTHcollectionheader  class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:[YTHcollectionheader headerViewIdentifier]];
        
    }
    return _collectionView;
}

#pragma mark - colection代理和数据源
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
         return CGSizeMake(SCREEN_W/4,AfW(80));
    }else{
         return CGSizeMake(SCREEN_W-AfW(24),AfW(125));
    }
 
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (section==0) {
        return 8;
    }else{
        return 2;
    }
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 2;
}

-(UICollectionReusableView*)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if([kind isEqualToString:UICollectionElementKindSectionHeader]){
        YTHcollectionheader *supplementaryView = [YTHcollectionheader headerViewWithCollectionView:collectionView forIndexPath:indexPath];
        if (indexPath.section==0) {
            supplementaryView.textLabel.text=@"资讯详情";
        }else{
            supplementaryView.textLabel.text=@"专家推荐";
        }
        return supplementaryView;
    }else if([kind isEqualToString:UICollectionElementKindSectionFooter]) {
        //            YTHcollectionheader *supplementaryView = [YTHcollectionheader headerViewWithCollectionView:collectionView forIndexPath:indexPath];
        //            supplementaryView.textLabel.text=@"销量管理";
        //            return supplementaryView;
    }
    return nil;
}
//collectionView距离上左下右位置设置
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    if (section==0) {
        return UIEdgeInsetsMake(0,0,0,0);
    }else{
        return UIEdgeInsetsMake(0,12,0,12);
    }
  
}
// collectionView之间最小列间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}
//collectionView之间最小行间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
      if (section==1) {
         return AfW(13);
      }
      return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        static NSString * cellID = @"YTHomeCollectionCell";
        YTHomeCollectionCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    
        cell.iconView.image=IMAGE(self.iconarray[indexPath.item]);
        cell.titleLabel.text=self.titlearray[indexPath.item];
        return cell;
    }else{
        static NSString * cellID = @"YTDisCollectionCell";
        YTDisCollectionCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    
//        if (indexPath.item==0) {
//            cell.iconView.image=IMAGE(@"discellleft_");
//        }else{
//            cell.iconView.image=IMAGE(@"discellright_");
//        }
        
        return cell;
    }
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0) {
        if (indexPath.item==0) {
            YTWebViewVC*webvc=[YTWebViewVC new];
            webvc.hidesBottomBarWhenPushed = YES;
            webvc.urlStr=@"https://m.qyun88.com/kj/index.php?platform=app";
            [self.navigationController pushViewController:webvc animated:1];
            
        }else if(indexPath.item==1){
            YTDisNoticeVC*vc=[YTDisNoticeVC new];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }else if(indexPath.item==2){
            YTDisNewsVC*vc=[YTDisNewsVC new];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }else {
            YTAdRecommendVC*vc=[YTAdRecommendVC new];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            
    }
}
@end
